import router from "./router";
import getPageTitle from "./utils/pageTitle";
import NProgress from "nprogress";
NProgress.configure({ showSpinner: false });
const whiteList = ["/login"];
router.beforeEach((to, from, next) => {
  NProgress.start();
  document.title = getPageTitle(to.meta.title);
  // const hasToken = getToken();
  // if (hasToken) {
  //   if (to.path === "/login") {
  // next({ path: "/" });
  //     NProgress.done();
  //   } else {
  //     if (store.getters.roles.length === 0) {
  //       isRelogin.show = true;
  //       store.dispatch("user/getInfo").then(() => {
  //         isRelogin.show = false;
  //         store.dispatch("GenerateRoutes").then((accessRoutes) => {
  //           router.addRoute(accessRoutes);
  //           next({ ...to, replace: true });
  //         });
  //       });
  //     } else {
  //       next();
  //     }
  //   }
  // } else {
  //   if (whiteList.indexOf(to.path) !== -1) {
  //     next();
  //   } else {
  //     next("/login");
  //     NProgress.done();
  //   }
  // }
  if (to.path === "/login") {
    next({ path: "/" });
    NProgress.done();
  } else {
    next();
  }
});

router.afterEach(() => {
  NProgress.done();
});
